    <div id="loading-image" style="display: none">
        <img src="<?php echo image_url('loading.gif') ?>"/>
    </div>
    <form id="form-bid" method="POST">
        <div class="col-lg-12 col-md-12 col-sm-12 no-padding">
            <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 bid-step bid-step-1">
                <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 bid-group">
                    <span class="unit-price">$</span>
                    <input data-original-title="<?php echo $this->lang->line('step-1-tooltip')?>" data-toogle="tooltip" name="bidAmt" id="bidAmt" autocomplete="off" type="text" required
                               value="<?php if (isset($bid->bid_amount)) echo $bid->bid_amount; else echo set_value('bidAmt'); ?>"
                               class="bid-tooltip form-control">
                </div>
                <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-16 label-bid"><?php echo $this->lang->line("Bid Price")?></div>
            </div>
            <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12 bid-step bid-step-2">
            	<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 bid-group">
                    <span class="unit-price"><?php echo $this->lang->line("days")?></span>
                    <input id="days" data-original-title="<?php echo $this->lang->line('step-2-tooltip')?>" data-toogle="tooltip" type="text" required
                               value="<?php if (isset($bid->bid_days)) echo $bid->bid_days; else echo set_value('days'); ?>"
                               name="days" class="bid-tooltip form-control">
                </div>
                <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-16 label-bid"><?php echo $this->lang->line("Time of Bid")?></div>
            </div>
            <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12 bid-step bid-step-3">
            	<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 bid-group">
                    <span   class="unit-price">$</span>
                    <input type="text" data-toggle="tooltip" id="escrow_flag" data-original-title="<?php echo $this->lang->line('step-3-tooltip')?>" required name="escrow_flag" value="" class="bid-tooltip form-control">
                </div>
                <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-16 label-bid"><?php echo $this->lang->line("escrow_flag")?></div>
            </div>
            <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12 bid-step bid-step-4">
            	<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 bid-group">
                    <input type="hidden" name="project_id" value="<?php echo $project->id; ?>">

		            <button data-toggle="tooltip" data-original-title="<?php echo $this->lang->line('step-4-tooltip')?>" type="submit" name="postBid" value="submit" class="bid-tooltip col-lg-12 col-sm-12 col-md-12 col-xs-12 btn btn-bid btn-lg"><i class="icon-bid"></i>
		            </button>

                </div>
                <div id="button-bid" class="col-lg-12 col-sm-12 col-md-12 col-xs-12 x8-16 label-bid"><?php echo $this->lang->line("Place Bid")?></div>
            </div>
        </div>


        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding line-bid-receive">
        	<div class="bid-receive">
        		<div style="display:inline-block;background: #f9f9f9;padding: 0 10px;">
		        	<?php echo $this->lang->line("received")?> <span class="unit-price">$</span>
		        	<span id="bid-receive">
                        0
		            </span>
                    <input type="hidden" name="bid_paid" id="bid_paid" value="">
	            </div>
            </div>
        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
        	<div class="col-md-12 no-padding quote-first-35"></div>
            <div class="col-md-12 quote-content">
	            <?php echo $this->lang->line("quote")?>
            </div>
            <div class="col-md-12 no-padding quote-last-35"></div>
        </div>
        <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 no-padding bid-comment">
            <textarea class="form-control" id="bid_desc" name="bid_desc" rows="5" placeholder="<?php echo $this->lang->line("placeholder_bid_comment")?>"></textarea>
            <input type="hidden" name="creator_id" value="<?php echo $project->creator_id?>"
        </div>
    </form>





<script>

    <?php
        if(!isProgrammer() || isset($this->loggedInUser->id) && $project->creator_id == $this->loggedInUser->id  ){
    ?>
        $(".bid").css("opacity","0.5");
        $(".btn-bid").attr("disabled","disabled");
        $("#form-bid input").attr("disabled","disabled");
    <?php } ?>

    $.validator.addMethod('lessThan',function(value,element,param){
        if(this.optional(element)) return true;
        var j = parseInt(value);
        var i = parseInt($('#bidAmt').val());
        return j < i;
    },'Yêu cầu đặt cọc phải nhỏ hơn giá bid');
    $("#form-bid").validate({
        rules: {
            "bidAmt": {
                required: true,
                digits: true,
                min :5
            },
            "days": {
                required: true,
                digits: true
            },
            "escrow_flag": {
                required: true,
                digits: true,
                lessThan : $('#escrow_flag').val()
            },
            "bid_desc": {
                required: true
            }
        },
        messages: {
            "bidAmt": {
                required: "<?php echo $this->lang->line('Your Bid')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Your Bid')." ".$this->lang->line('numeric') ?>",
                min : "<?php echo $this->lang->line('Your Bid')." ".$this->lang->line('min')?>5"
            },
            "days": {
                required: "<?php echo $this->lang->line('Days')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Days')." ".$this->lang->line('numeric') ?>"
            },
            "escrow_flag": {
                required: "<?php echo $this->lang->line('Milestone Request')." ".$this->lang->line('required') ?>",
                digits: "<?php echo $this->lang->line('Milestone Request')." ".$this->lang->line('numeric') ?>"
            },
            "bid_desc": {
                required: "<?php echo $this->lang->line('Bid desc')." ".$this->lang->line('required') ?>"
            }
        },
        showErrors: function(errorMap,errorList){
            $.each(this.successList,function(index,value){
               return $(value).popover('hide');
            });
            return $.each(errorList,function(index,value){
               var _popover;
                _popover = $(value.element).popover({
                    trigger: "manual",
                    placement: "bottom",
                    content: value.message,
                    template: "<div class=\"popover\"><div class=\"arrow\"></div><div class=\"popover-inner\"><div class=\"popover-content\"><p></p></div></div></div>"
                });
                 _popover.data("bs.popover").options.content = value.message;
                return $(value.element).popover("show");
            });
        },
        submitHandler: function (form) {
            $.ajax({
                type: "POST",
                url: "<?php echo base_url()."index.php/project/createBid"?>",
                data: $("#form-bid").serializeArray(),
                //data : "data=1244443",
                beforeSend: function () {
                    $('#loading-image').show();
                },
                success: function (data) {
                    $('#loading-image').hide();
                    data = $.parseJSON(data);
                    if (data.status == 'error') {
                        $('#error-bid').html(data.message);
                    } else {
                        console.log(data.data);
                        $('#button-bid').val('<?php echo $this->lang->line('Edit Bid')?>');
                        $(".bid").load('<?php echo base_url()."index.php/project/editBid"?>', {project_id:<?php echo $project->id?>});
                        $(".num-bid").html(data.num);
                        $('html, body').animate({
                            scrollTop: ($('#list-freelancer-bid').offset().top)
                        }, 500);
                        $('#list-freelancer-bid').load("<?php echo base_url()."index.php/project/listFreelancerBid/".$project->id?>");
                    }
                }
            });
        }
    });

</script>